﻿@(Html.DevExtreme().DataGrid<DevExtreme.NETCore.Demos.Models.Northwind.Order>()
    .DataSource(d => d.Mvc()
        .Controller("DataGridWebApi")
        .LoadAction("Orders")
        .InsertAction("InsertOrder")
        .UpdateAction("UpdateOrder")
        .DeleteAction("DeleteOrder")
        .Key("OrderID")
    )
    .RemoteOperations(true)
    .Columns(columns => {
        columns.AddFor(m => m.CustomerID)
            .Lookup(lookup => lookup
                .DataSource(d => d.Mvc().Controller("DataGridWebApi").LoadAction("CustomersLookup").Key("Value"))
                .ValueExpr("Value")
                .DisplayExpr("Text")
            );

        columns.AddFor(m => m.OrderDate);

        columns.AddFor(m => m.Freight)
            .HeaderFilter(f => f.GroupInterval(100));

        columns.AddFor(m => m.ShipCountry);

        columns.AddFor(m => m.ShipVia)
            .Lookup(lookup => lookup
                .DataSource(d => d.Mvc().Controller("DataGridWebApi").LoadAction("ShippersLookup").Key("Value"))
                .ValueExpr("Value")
                .DisplayExpr("Text")
            );

    })
    .FilterRow(f => f.Visible(true))
    .HeaderFilter(f => f.Visible(true))
    .GroupPanel(p => p.Visible(true))
    .Scrolling(s => s.Mode(GridScrollingMode.Virtual))
    .Height(600)
    .ShowBorders(true)
    .MasterDetail(md => md
        .Enabled(true)
        .Template(@<text>

            @(Html.DevExtreme().DataGrid()
                .DataSource(d => d.Mvc()
                    .Controller("DataGridWebApi")
                    .LoadAction("OrderDetails")
                    .LoadParams(new { orderID = new JS("data.OrderID") })
                )
                .ShowBorders(true)
            )

        </text>)
    )
    .Editing(e => e.AllowAdding(true).AllowDeleting(true).AllowUpdating(true))
    .Grouping(g => g.AutoExpandAll(false))
    .Summary(s => s
        .TotalItems(totalItems => {
            totalItems.AddFor(m => m.Freight).SummaryType(SummaryType.Sum);
        })
        .GroupItems(groupItems => {
            groupItems.AddFor(m => m.Freight).SummaryType(SummaryType.Sum);

            groupItems.Add().SummaryType(SummaryType.Count);
        })
    )
)
